package net.citigo.tool.s3backup;

import java.io.File;
import java.io.FileInputStream;
import java.util.Date;
import java.util.Properties;
import java.util.Timer;

public class App 
{
	private final Timer timer = new Timer();
    private final int days;
    
    public static final String WORKING_FOLDER = "local.workingfolder";
    public static final String BACKUP_FOLDER = "local.backupfolder";
    public static final String FILE_NAME = "filename";
    public static final String BUCKET = "s3.bucket";
    public static final String OBJECT_NAME = "s3.objectname";
	
    public App(int days) {
        this.days = days;
    }
    
    public void start() {
    	try {
        	File s3cred = new File("s3cred.properties");
        	Properties config = new Properties();
        	config.load(new FileInputStream("config.properties"));
        	BackupTool tool = new BackupTool(s3cred, config);
            timer.scheduleAtFixedRate(tool, new Date(), days * 24 * 60 * 60 * 1000);    		
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
    }
	
    public static void main( String[] args )
    {
        if (args.length != 1) {
        	System.out.println("Command: java -jar <filename> <rate in days>");
        	System.exit(1);
        }
        new App(Integer.parseInt(args[0])).start();
    }
}
